package net.xinqushi.nio;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOTest {


    public static void main(String[] args) throws IOException {
        RandomAccessFile aFile = new RandomAccessFile(TSET_FILE_NAME, "rw");
        FileChannel inChannel = aFile.getChannel();

        ByteBuffer buf = ByteBuffer.allocate(48);

        int bytesRead = inChannel.read(buf);
        while (bytesRead != -1) {

            System.out.println("Read " + bytesRead);
            buf.flip();

            while(buf.hasRemaining()){
                System.out.print((char) buf.get());
            }

            buf.clear();
            bytesRead = inChannel.read(buf);
        }
        aFile.close();
    }

    static void testFile(){
        try {
            FileInputStream fis = new FileInputStream(TSET_FILE_NAME);
            //fis.getFD();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private final static String  TSET_FILE_NAME = "D:\\test\\test.txt";


}
